<html lang="zh-CN">
<head>
	<title>收藏夹</title>
	<meta charset="UTF-8">
	<meta name="viewport" content=" initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="format-detection" content="telephone=no">
	<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/zepto.1.1.3.min.js{$Think.config.RESOURCE_VER}"></script>
	<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/alertMsg.js{$Think.config.RESOURCE_VER}"></script>
	<script src="{$Think.config.RESOURCEURL}wx_assets/js/util.js{$Think.config.RESOURCE_VER}" type="text/javascript"></script>
	<script type="text/javascript" src="{$Think.config.RESOURCEURL}wx_assets/js/share_product.js{$Think.config.RESOURCE_VER}"></script>
	<link rel="stylesheet" href="{$Think.config.RESOURCEURL}wx_assets/css/common.css{$Think.config.RESOURCE_VER}" onerror="_cdnFallback(this)">
	<link href="{$Think.config.RESOURCEURL}wx_assets/css/product_list.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
	<link href="{$Think.config.RESOURCEURL}wx_assets/css/product_templates.css{$Think.config.RESOURCE_VER}" rel="stylesheet">
</head>
<body>
<notempty name="headerTpl">
	<include file="$headerTpl" />
</notempty>
<div class="condition">
	<div id="favorite">
	</div>
	<div class="qb_tac qb_none" style="height: 30px;" evttag="loadMore"
		 id="load-more"></div>
</div>
<div class="qb_quick_tip qb_none" id="bubble"></div>
<notempty name="footerTpl">
	<include file="$footerTpl" />
</notempty>
<script type="text/html" id="Tpl">
	<%for(var i=0;i<favorites.length;i++){
	var favorite = favorites[i];
	%>
	<div class="main fav" onclick="favorite.onDetail('<%=favorite.fromCustomerId%>','<%=favorite.id%>','<%=favorite.sId%>');">
		<div class="imgDiv" align="center">
			<img src="<%=favorite.picUrl%>" onload="$.util.imgCenter(this)">
		</div>
		<div class="title">
			<%=favorite.name%>
		</div>
		<div class="priceDiv">
			<%if(favorite.freeBuy=='1'){%>
			<span class="price">售价：￥<%=freebuyPrice(favorite.freeBuyMoney);%></span>
			<%}else if(favorite.teambuy=='1'){%>
			<span class="price">售价：￥<%=favorite.teamPrice%></span>
			<%}else if(favorite.playType=='5'&&isEnjoyMiPrice=='1'){%>
			<%if(favorite.supportSpecification=='1'&&favorite.minMiPrice!=favorite.maxMiPrice){%>
			<span class="price">售价：￥<%=favorite.minMiPrice%>~<%=favorite.maxMiPrice%></span>
			<%}else if(favorite.supportSpecification=='1'){%>
			<span class="price">售价：￥<%=favorite.minMiPrice%></span>
			<%}else{%>
			<span class="price">售价：￥<%=favorite.miPrice%></span>
			<%}%>
			<%}else if(favorite.supportSpecification=='1'){%>
			<%if(favorite.minDisPrice>0&&favorite.minDisPrice!=favorite.maxDisPrice){%>
			<span class="price">售价：￥<%=favorite.minDisPrice%>~<%=favorite.maxDisPrice%></span>
			<%}else if(favorite.minDisPrice>0){%>
			<span class="price">售价：￥<%=favorite.minDisPrice%></span>
			<%}else if(favorite.minFixedPrice!=favorite.maxFixedPrice){%>
			<span class="price">售价：￥<%=favorite.minFixedPrice%>~<%=favorite.maxFixedPrice%></span>
			<%}else{%>
			<span class="price">售价：￥<%=favorite.minFixedPrice%></span>
			<%}%>
			<%}else{%>
			<%if(favorite.discountedPrice==null){%>
			<span class="price">售价：￥<%=favorite.fixedPrice%></span>
			<%}else{%>
			<span class="price">售价：￥<%=favorite.discountedPrice%></span>
			<%}%>
			<%}%>
			<a class="collection" onclick="favorite.collection(this,'<%=favorite.id%>');">取消收藏</a>
		</div>
	</div>
	<%}%>
</script>
<script>
	template.helper("freebuyPrice",function(price){
		var price = price.split(",");
		var length = price.length;
		if(length>1){
			return price[0]+"~<i>&yen;</i>"+price[length-1];
		}else{
			return price[0];
		}
	});
</script>
<script>
	var hrefParamsArray = GetSessionIdFromHref(window.location.search);
	hrefParamsArray["userName"]="{$userName}";

	function GetSessionIdFromHref(search){
	　　	var args = search.substring(1);
　　				var retval = new Array();
		args = args.split("&");
		for(var i = 0; i < args.length; i ++){
			str = args[i];
			var arg = str.split("=");
			if(arg.length <= 1) continue;

			if(arg[0] == 'params') {
				var params = decodeURIComponent(arg[1]);
				var obj = eval('(' + params + ')');
				if (obj.rootid != undefined) {
					retval["rootid"] = obj.rootid;
				}
				if (obj.start != undefined) {
					retval["start"] = obj.start;
				}
				if (obj.tplid != undefined) {
					retval["tplid"] = obj.tplid;
				}
			} else if(arg[0] == 'customerId') {
				retval["customerId"] = arg[1];
			}else if(arg[0] == 'userName'){
				retval["userName"] = arg[1];
			}
		}
		if (retval["start"] == undefined) {
			retval["start"] = 0;
		}
		return retval;
	}
	var baseUrl = '{$Think.config.SERVER_HOST}';
	var favorite={
		pageSize:10,
		page:0,
		init:function(){
			var me=this;
			this._initEvent();
			$.util.pageLoading.show();
			me._loadList(me.page,function(){
				$.util.pageLoading.hide();
			});
		},
		_initEvent:function(){
			var me=this;
			$.util.initDataLoading({
				me:favorite,
				lastChildren:function(){
					return $("#favorite .main:last");
				},
				page:function(){
					return favorite.page;
				},
				pageCount:function(){
					return favorite.pageCount;
				}
			});
		},
		_renderList:function(data,page,callback){
			var me=this;
			if(data){
				var html=template("Tpl", data),
						container = $("#favorite");
				container.append(html);
				me.page=page;
				me.pageCount=data.pageCount;
				callback && callback();
			}
		},
		_loadList:function(page,callback){
			var me=this;
			$.req.get("call.json?module=product&customerId={$customerId}&method=getFavorite",{
				userName:"{$userName}",
				params: {"tplid":1,"start":page,
					"limit":me.pageSize}
			},function(data){
				if(data){
					me._renderList(data,page,callback);
				}
			});
		},
		onDetail:function (formCustomerId,pId,sId) {
			var p={
				sId:sId,
				id:pId
			};
			p=encodeURIComponent(JSON.stringify(p));
			var detailUrl=baseUrl+'call.html?customerId='+formCustomerId+'&module=product&method=getProduct&params='+p;
			location.href=detailUrl;
		},
		collection:function (ctrl,id){
			window.event.cancelBubble = true;
			var b = {
				'module': 'product',
				'method' : 'removeFavorite',
				'params' : '{"id":' + id+ ',"username":"'+hrefParamsArray['userName']+'"}'
			};

			$.ajax({
				url: 'call.json?userName=' + hrefParamsArray["userName"] + '&customerId=' + hrefParamsArray["customerId"],
				dataType: "json",
				type: "POST",
				data: b,
				success : function (b) {
					$(ctrl).parents(".main").remove();
				},
				error:function(){
					alert();
				}
			});

		}
	}
	favorite.init();
</script>
<script type="text/javascript" src="wx_assets/js/zepto_product.js?v=201401121"></script>
<script type="text/javascript">
	function resetAndAppendHerf(search){
	　　	var args = search.substring(1);
　　	var retval = new Array();
		args = args.split("&");
		for(var i = 0; i < args.length; i ++){
			str = args[i];
			var arg = str.split("=");
			if(arg.length <= 1) continue;
			if(arg[0] == 'userName'){
				args[i] = "userName=";
			}
		}
		return args.join("&");
	}

	$(function(){
		var imageUrl = '';
		var title = '我的收藏';
		var des = '点击这里查看我收藏的商品';
		var search = '?' + resetAndAppendHerf(window.location.search);
		var shareUrlString = window.location.protocol + "//"
				+ window.location.host + window.location.pathname + search;

		window.shareData = {
			"imgUrl": imageUrl,
			"timeLineLink":  shareUrlString ,
			"sendFriendLink":  shareUrlString ,
			"weiboLink":  shareUrlString ,
			"tTitle": title,
			"tContent": des,
			"fTitle": title,
			"fContent": des,
			"wContent": des
		};
		document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
			// 发送给好友
			WeixinJSBridge.on('menu:share:appmessage', function (argv) {
				WeixinJSBridge.invoke('sendAppMessage', {
					"img_url":  window.shareData.imgUrl,
					"img_width": "640",
					"img_height": "640",
					"link": window.shareData.sendFriendLink,
					"desc": window.shareData.fContent,
					"title": window.shareData.fTitle
				}, function (res) {
					_report('send_msg', res.err_msg);
				})
			});

			// 分享到朋友圈
			WeixinJSBridge.on('menu:share:timeline', function (argv) {
				WeixinJSBridge.invoke('shareTimeline', {
					"img_url": window.shareData.imgUrl,
					"img_width": "640",
					"img_height": "640",
					"link": window.shareData.timeLineLink,
					"desc": window.shareData.tContent,
					"title": window.shareData.tTitle
				}, function (res) {
					_report('timeline', res.err_msg);
				});
			});

			// 分享到微博
			WeixinJSBridge.on('menu:share:weibo', function (argv) {
				WeixinJSBridge.invoke('shareWeibo', {
					"content": window.shareData.wContent,
					"url": window.shareData.weiboLink
				}, function (res) {
					_report('weibo', res.err_msg);
				});
			});
		});
	});
</script>
</body>
</html>